package com.hdc.hdc.mainmenu2.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hdc.hdc.mainmenu2.entity.Content;
import com.hdc.hdc.mainmenu2.entity.CustomerCompany;
import com.hdc.hdc.mainmenu2.entity.ProductNav;
import com.hdc.hdc.mainmenu2.service.CompanyServiceI;
import com.hdc.hdc.mainmenu2.service.ContentServiceI;
import com.hdc.hdc.mainmenu2.service.ProductServiceI;

/**
 * 主页的所有跳转
 * @author gxy
 *
 * @date 2018年4月6日 下午12:41:58
 *
 *
 * sucess dependency on not give up
 *
 */
@Controller
@RequestMapping("/showAll")
public class ShowAllPageController {
	
	private static final Logger log = LoggerFactory.getLogger(ShowAllPageController.class);
	
	private final String FLODER_NAME = "/content";
	
	@Autowired
	private CompanyServiceI companyServiceI;
	
	@Autowired
	private ContentServiceI contentServiceI;
	
	@Autowired
	private ProductServiceI productServiceI;
	
	@RequestMapping("/headBot/{companyCode}")
	public String showHeadBot(@PathVariable String companyCode,Model model) {
		
		
		log.info("加载："+companyCode+"的headBot,这个不需要 返回数据，只需要返回一个公司Logo");
		
		CustomerCompany company = this.companyServiceI.getCompanyMessageByCode(companyCode);
		
		model.addAttribute("companyCode", companyCode);
		model.addAttribute("company", company);
		
		return this.FLODER_NAME+"/header";
	}
	
	@RequestMapping("/bannerTop/{companyCode}")
	public String showBannerTop(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的bannerTop");
		
		CustomerCompany company = this.companyServiceI.getCompanyMessageByCode(companyCode);
		
		model.addAttribute("companyCode", companyCode);
		
		model.addAttribute("company", company);
		
		return this.FLODER_NAME+"/bannerTop";
	}
	
	@RequestMapping("/bannerGrid/{companyCode}")
	public String showBannerGrid(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的bannerGrid");
		
		CustomerCompany company = this.companyServiceI.getCompanyMessageByCode(companyCode);
		
		model.addAttribute("companyCode", companyCode);
		model.addAttribute("company", company);
		
		return this.FLODER_NAME+"/banner_grid";
	}
	
	@RequestMapping("/content/{companyCode}")
	public String showContent(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的content");
		
		Content content = this.contentServiceI.getContentByCompanyCode(companyCode);
		
		model.addAttribute("companyCode", companyCode);
		
		model.addAttribute("content", content);
		
		return this.FLODER_NAME+"/content";
	}
	
	@RequestMapping("/contentBottom/{companyCode}")
	public String showContentBottom(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的contentBottom");
		
		Content content = this.contentServiceI.getContentByCompanyCode(companyCode);
		
		model.addAttribute("companyCode", companyCode);
		
		model.addAttribute("content", content);
		
		return this.FLODER_NAME+"/contentBottom";
	}
	
	@RequestMapping("/productNav/{companyCode}")
	public String showProductNav(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的productNav");
		
		model.addAttribute("companyCode", companyCode);
		
		List<ProductNav> products = this.productServiceI.getProductByCompanyCode(companyCode);
		
		model.addAttribute("products", products);
		
		return this.FLODER_NAME+"/productNav";
	}
	
	@RequestMapping("/couponsNav/{companyCode}")
	public String showCouponsNav(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的couponsNav");
		
		model.addAttribute("companyCode", companyCode);
		
		return this.FLODER_NAME+"/couponsNav";
	}
	
	@RequestMapping("/footerNav/{companyCode}")
	public String showFooterNav(@PathVariable String companyCode,Model model) {
		
		log.info("加载："+companyCode+"的footerNav");
		
		CustomerCompany company = this.companyServiceI.getCompanyMessageByCode(companyCode);
		
		model.addAttribute("companyCode", companyCode);
		model.addAttribute("company", company);
		
		return this.FLODER_NAME+"/footerNav";
	}
	

}
